using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NCS.Library.Utilities;
using NCS.Module.Multimedia.Library.Gallery;
using NCS.Module.Multimedia.Library.Providers;

namespace NCS.Module.Multimedia.Library.Bonus
{
    public class Gallery_CateBonusController
    {
        public static DataTable GetCateBonus()
        {
            return DataAccessProvider.instance().GetCateBonus();
        }

        public static DataTable GetAllGalleryByKey(string txtSearch, DateTime fromdate, DateTime todate, int userid)
        {
            return DataAccessProvider.instance().GetAllGalleryByKey(txtSearch, fromdate, todate, userid);
        }

        public static DataTable GetCateBonusByNum(int num)
        {
            return DataAccessProvider.instance().GetCateBonusByNum(num);
        }
        public static DataTable GetAllCateBonus()
        {
            return DataAccessProvider.instance().GetAllCateBonus();
        }

        public static DataTable GetAllCateBonusbyOther(string txtSearch, DateTime fromdate, DateTime todate, int userid)
        {
            return DataAccessProvider.instance().GetAllCateBonusbyOther(txtSearch, fromdate, todate, userid);
        }

       


        public static void SetCateBonusIndex(int id, int index)
        {
            DataAccessProvider.instance().SetCateBonusIndex(id, index);
        }

        public static void SetCateBonusRank(int id, int rank)
        {
            DataAccessProvider.instance().SetCateBonusRank(id, rank);
        }

        public static DataTable GetAllCateBonusByParentID(int parentid)
        {
            return DataAccessProvider.instance().GetAllCateBonusByParentID(parentid);
        }

        public static DataTable GetAllCateBonusByParentID(int _CateBonus_parentID, int portalid, int pagesize, int currpage, out int totalRecord)
        {
            return DataAccessProvider.instance().GetAllCateBonusByParentID(_CateBonus_parentID, portalid, pagesize, currpage, out totalRecord);
        }

        public static void SetCateBonusStatus(int id, bool status)
        {
            DataAccessProvider.instance().SetAlbumStatus(id, status);
        }

        public static void DeleteCateBonus(int _catebonus_ID)
        {
            DataAccessProvider.instance().DeleteCateBonus(_catebonus_ID);
        }

        public static int InsertCatebonus(Gallery_CateBonusInfo _catebonusInfo)
        {
            return DataAccessProvider.instance().InsertCateBonus(_catebonusInfo);
        }

        public static void UpdateAlbum(Gallery_CateBonusInfo _catebonusInfo)
        {
            DataAccessProvider.instance().UpdateCateBonus(_catebonusInfo);
        }

        public static Gallery_CateBonusInfo GetCateBonus(int _catebonus_ID)
        {
            return DataAccessProvider.instance().GetCateBonus(_catebonus_ID);
        }

        public static Gallery_AlbumInfo GetAlbumByOtherID(int otherid)
        {
            return DataAccessProvider.instance().GetAlbumByOtherID(otherid);
        }
        public static DataRow[] GetCateBonusByParentID(DataTable dtRole, int parentID)
        {
            DataRow[] retVal = null;
            retVal = dtRole.Select("CateBonusParentID = " + parentID);
            return retVal;
        }
        public static DataTable GetCateBonusByParentID(DataTable dtCateBonus, DataTable dtReturnAlbum)
        {
            DataRow[] dtItems = GetCateBonusByParentID(dtCateBonus, 0);
            foreach (DataRow row in dtItems)
            {
                DataRow rowItem = dtReturnAlbum.NewRow();

                rowItem["CateBonusID"] = row["CateBonusID"].ToString();
                rowItem["CateBonusParentID"] = row["CateBonusParentID"];
                rowItem["CateBonusAvatar"] = row["CateBonusAvatar"];
                rowItem["CateBonusName"] = row["CateBonusName"].ToString();
                rowItem["CateBonusDetail"] = row["CateBonusDetail"];
                rowItem["Visible"] = row["Visible"];
                rowItem["Visible"] = row["Visible"];
                rowItem["Rank"] = row["Rank"];
                rowItem["Level"] = "0";

                dtReturnAlbum.Rows.Add(rowItem);
                LoadCateBonusForCur(dtCateBonus, rowItem, dtReturnAlbum);
            }
            return dtReturnAlbum;
        }
        public static DataTable LoadCateBonusForCur(DataTable dtCateBonus, DataRow curItem, DataTable dtReturnAlbum)
        {
            int level = Convert.ToInt32(curItem["Level"]);
            level += 1;
            int _CateBonusID = Convert.ToInt32(curItem["CateBonusID"]);
            DataRow[] dtChild = GetCateBonusByParentID(dtCateBonus, _CateBonusID);
            foreach (DataRow row in dtChild)
            {
                DataRow childItem = dtReturnAlbum.NewRow();

                childItem["CateBonusID"] = row["CateBonusID"].ToString();
                childItem["CateBonusParentID"] = row["CateBonusParentID"];
                childItem["CateBonusAvatar"] = row["CateBonusAvatar"];
                childItem["CateBonusName"] = MiscUtility.StringIndent(level) + row["CateBonusName"].ToString();
                childItem["CateBonusDetail"] = row["CateBonusDetail"];
                childItem["Visible"] = row["Visible"];
                childItem["Rank"] = row["Rank"];
                childItem["Indexs"] = row["Indexs"];
                childItem["Level"] = level;
                dtReturnAlbum.Rows.Add(childItem);
                LoadCateBonusForCur(dtCateBonus, childItem, dtReturnAlbum);
            }
            return dtReturnAlbum;
        }
	    
    }
}
